package com.zego.wawaji.ui.coupon.bean;

import com.zego.wawaji.base.data.BaseData;

import org.json.JSONArray;

import java.util.ArrayList;
import java.util.List;

/**
 * 优惠券列表
 * Created by Su on 2018/2/24.
 */
public class CouponList extends BaseData {
    private List<Coupon> couponList = new ArrayList<>();

    private List<Coupon> couponEnableList = new ArrayList<>();  // 可使用
    private List<Coupon> couponUsedList = new ArrayList<>();    // 已使用
    private List<Coupon> couponInvalidList = new ArrayList<>(); // 已失效

    @Override
    public void parseJson(String jsonStr) {
        JSONArray jsonArray = getJsonArray(jsonStr);
        this.couponList = (List<Coupon>) getBaseDataList(jsonArray, Coupon.class);
    }

    public List<Coupon> getCouponList() {
        return couponList;
    }

    /**
     * 可使用列表
     */
    public List<Coupon> getCouponEnableList() {
        if (couponEnableList == null)
            couponEnableList = new ArrayList<>();
        couponEnableList.clear();

        for (Coupon coupon : couponList) {
            if (coupon.getCouponStatus() == 1) {
                couponEnableList.add(coupon);
            }
        }
        return couponEnableList;
    }

    /**
     * 已使用列表
     */
    public List<Coupon> getCouponUsedList() {
        if (couponUsedList == null)
            couponUsedList = new ArrayList<>();
        couponUsedList.clear();

        for (Coupon coupon : couponList) {
            if (coupon.getCouponStatus() == -1) {
                couponUsedList.add(coupon);
            }
        }
        return couponUsedList;
    }

    /**
     * 已过期列表
     */
    public List<Coupon> getCouponInvalidList() {
        if (couponInvalidList == null)
            couponInvalidList = new ArrayList<>();
        couponInvalidList.clear();

        for (Coupon coupon : couponList) {
            if (coupon.getCouponStatus() == -2) {
                couponInvalidList.add(coupon);
            }
        }
        return couponInvalidList;
    }
}
